﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;

namespace IronOne.SalesOne.SalesOneWeb.SalesQuotations
{
    public partial class ViewReport : System.Web.UI.Page
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {
            string quoNum = Session["quotationNum"].ToString();
            //quoNumber = quoNum;
            string planCode = Session["planCode"].ToString();
            string soCode = Session["soCode"].ToString();


            Report rpt = new Report();
            rpt.DataSourceConnections[0].SetConnection("SAJITH-PC", "SalesOne", "sa", "saadmin@1");          
            rpt.SetParameterValue("Quat", quoNum);

            CrystalReportViewer1.ReportSource = rpt;
            

        }


        private void ReportParameter()
        {

        //CrystalReportViewer1.RefreshReport();
        ParameterFields paramFields = new ParameterFields();
        ParameterField pfItemYr = new ParameterField();
        pfItemYr.ParameterFieldName = "Quat"; //year is Crystal Report Parameter name.
        ParameterDiscreteValue dcItemQno = new ParameterDiscreteValue();

        //dcItemQno.Value = quoNumber;       
        //dcItemYr.Value = DropDownList1.SelectedValue;
        pfItemYr.CurrentValues.Add(dcItemQno);
        paramFields.Add(pfItemYr);

        CrystalReportViewer1.ParameterFieldInfo = paramFields;
        

        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/SalesQuotations/SearchSalesQuatation.aspx");
        }

        protected void btnPdf_Click(object sender, EventArgs e)
        {
            Report rpt = new Report();
            rpt.DataSourceConnections[0].SetConnection("SAJITH-PC", "SalesOne", "sa", "saadmin@1");
            rpt.SetParameterValue("Quat", 122);

            CrystalReportViewer1.ReportSource = rpt;
            
            MemoryStream oStream; // using System.IO
            oStream = (MemoryStream)
            rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(oStream.ToArray());
            Response.End();
        }
           

        
    }
}
